import numpy as np


def getRatioAndDeduct(fee):
    if fee <= 36000:
        return [3, 0]
    elif fee <= 144000:
        return [10, 2520]
    elif fee <= 300000:
        return [20, 16920]
    elif fee <= 420000:
        return [25, 31920]
    elif fee <= 660000:
        return [30, 52920]
    elif fee <= 960000:
        return [35, 85920]
    else:
        return [45, 181920]


if __name__ == "__main__":
    every = np.zeros((13, 4))  # 税前、社保公积金、个税、税后
    total = np.zeros((13, 4))
    every[1, :2] = [31793.11, 6495.59]
    every[2, :2] = [37477.71, 4530.97 - 1695]  # 社保公积金共2835.97
    every[3, :2] = [26000, 4552.37 - 1716.4]
    every[4, :2] = [27914.94, 4743.87 - 1907.9]
    every[5, :2] = [26000, 4552.37 - 1716.4]
    every[6, :2] = [29500, 4902.37 - 2066.4]
    every[7, :2] = [27327.59, 4685.13 - 1849.16]
    every[8, :2] = [28025.86, 6324.15 - 3488.18]
    every[9, :2] = [29403.45, 12949.46 - 10113.49]
    assume = 30000
    every[10, :2] = [assume, 2835.97]
    every[11, :2] = [assume, 2835.97]
    every[12, :2] = [assume, 2835.97]

    for i in range(1, 13):
        total[i] = np.sum(every[:i + 1], axis=0)
        shouldPayTax = total[i, 0] - total[i, 1] - 1000 * i - 5000 * i
        shouldPayTax = max(shouldPayTax, 0)
        [ratio, deduct] = getRatioAndDeduct(shouldPayTax)
        print(i, shouldPayTax, ratio)
        total[i, 2] = shouldPayTax * ratio / 100 - deduct
        every[i, 2] = total[i, 2] - total[i - 1, 2]
        every[i, 3] = every[i, 0] - every[i, 1] - every[i, 2]
        total[i, 3] = total[i - 1, 3] + every[i, 3]
    pass
